// 商品分类
<template>
  <div>
    <Row class="page">
      <Col span="24" gutter="10">
      <Modal v-model="modelDel" title="提醒" @on-ok="delok" @on-cancel="delcancel">
        <p>是否进行退款，点击确定退款，点击取消不退款！</p>
      </Modal>
      <Col span="8" style="">
      <Card :bordered="true" style="padding-bottom:30px;">
        <p slot="title">订单号查询</p>
        <Col span="20" style="padding-right:10px;">
        <Input v-model="ordergroupOrder" placeholder="订单号"></Input>
        </Col>
        <Col span="4">
        <Button type="primary" long @click.stop="orderBtn">查询</Button>
        </Col>
      </Card>
      </Col>
      <Col span="8" style="padding-left:10px;">
      <Card :bordered="true" style="padding-bottom:30px;">
        <p slot="title">姓名查询</p>
        <Col span="20" style="padding-right:10px;">
        <Input v-model="orderusername" placeholder="订单号"></Input>
        </Col>
        <Col span="4">
        <Button type="primary" long @click.stop="usernameBtn">查询</Button>
        </Col>
      </Card>
      </Col>
      <Col span="8" style="padding-left:10px;">
      <Card :bordered="true" style="padding-bottom:30px;">
        <p slot="title">电话查询</p>
        <Col span="20" style="padding-right:10px;">
        <Input v-model="ordertel" placeholder="订单号"></Input>
        </Col>
        <Col span="4">
        <Button type="primary" long @click.stop="telBtn">查询</Button>
        </Col>
      </Card>
      </Col>
      </Col>
    </Row>
    <br>
    <Row>
      <Col span="24">
      <Tabs value="name1" @on-click="click">
        <TabPane :label="label" name="name1">
          <Row>
            <Col span="24">
            <Table border :columns="columns7" :data="data6"></Table>
            </Col>

          </Row>
        </TabPane>
        <TabPane label="已付款" name="name2">
          <Col span="24">
          <Table border :columns="columns7" :data="data6"></Table>
          </Col>

        </TabPane>
        <TabPane label="已发货" name="name3">
          <Col span="24">
          <Table border :columns="columns7" :data="data6"></Table>
          </Col>

        </TabPane>
        <TabPane label="已收货" name="name4">
          <Col span="24">
          <Table border :columns="columns7" :data="data6"></Table>
          </Col>

        </TabPane>
        <TabPane label="拼团成功" name="name5">
          <Col span="24">
          <Table border :columns="columns7" :data="data6"></Table>
          </Col>

        </TabPane>
        <TabPane label="拼团失败" name="name6">
          <Col span="24">
          <Table border :columns="columns7" :data="data6"></Table>
          </Col>

        </TabPane>
      </Tabs>

      </Col>
    </Row>
    <br>
    <Row>
      <Page :total="1000000" :current.sync="currentpage" @on-change="pages" />
    </Row>
    <Modal v-model="modal2" title="订单详情">
      <Form ref="orderInfo" id="dy" :model="orderInfo" :label-width="110">

        <FormItem label="订单号 :" prop="name">

          <p>{{orderInfo.group_order}}</p>

        </FormItem>
        <FormItem label="订单时间 :" prop="name">

          <p>{{orderInfo.create_datetime}}</p>

        </FormItem>
        <FormItem label="订单状态 :" prop="name">

          <p v-if="orderInfo.order_status == 1">已付款</p>
          <p v-else-if="orderInfo.order_status == 2">拼团成功</p>
          <p v-else-if="orderInfo.order_status == 5">已退款</p>
        </FormItem>
        <FormItem label="配送方式 :" prop="name">
          <p>{{orderInfo.delivery_mode}}</p>
        </FormItem>
        <FormItem label="收货人姓名">
          <p>{{orderInfo.userName}}</p>
        </FormItem>
        <FormItem label="收货人电话">
          <p>{{orderInfo.tel}}</p>
        </FormItem>
        <FormItem label="收货人地址">
          <p>{{orderInfo.adds}}</p>
        </FormItem>
        <FormItem label="用户留言 :" prop="name">
          <p>{{orderInfo.remarks}}</p>
        </FormItem>
        <FormItem label="商品信息 :" prop="name">
          <div>
            <p>{{orderInfo.goods_name}}</p>
            <Row>
              <Col span="8">
              <p>数量:{{orderInfo.number}}</p>
              </Col>
              <Col span="8">
              <p>价格:{{orderInfo.price}}</p>
              </Col>
              <Col span="8">
              <p>规格:{{orderInfo.spec_name}}</p>
              </Col>

            </Row>
          </div>
        </FormItem>
        <FormItem label="订单金额:">
          <p>{{orderInfo.price}}</p>
        </FormItem>
        <img :src="orderimg" style="width:100%;" alt="">
      </Form>
      <div slot="footer">
        <Row>
          <Col span="18" offset="6">
          <div v-if="orderInfo.order_status == 0">
            <!-- <Button type="warning" @click.stop="fh(orderInfo.group_order)">确认发货</Button>
            <Button type="info" v-print="'#dy'">打印订单</Button> -->
            <Button type="error" @click="ok">取消</Button>
          </div>
          <div v-if="orderInfo.order_status == 1">
            <Button type="warning" @click.stop="fh(orderInfo.group_order)">确认发货</Button>
            <Button type="info" v-print="'#dy'">打印订单</Button>
            <Button type="error" @click="ok">取消</Button>
          </div>
          <div v-if="orderInfo.order_status == 2">
            <!-- <Button type="warning" @click.stop="fh(orderInfo.group_order)">确认发货</Button> -->
            <Button type="info" v-print="'#dy'">打印订单</Button>
            <Button type="error" @click="ok">取消</Button>
          </div>
          <div v-if="orderInfo.order_status == 3">
            <!-- <Button type="warning" @click.stop="fh(orderInfo.group_order)">确认发货</Button> -->
            <Button type="info" v-print="'#dy'">打印订单</Button>
            <Button type="error" @click="ok">取消</Button>
          </div>
          <div v-if="orderInfo.order_status == 5">
            <!-- <Button type="warning" @click.stop="fh(orderInfo.group_order)">确认发货</Button> -->
            <Button type="info" v-print="'#dy'">打印订单</Button>
            <Button type="error" @click="ok">取消</Button>
          </div>
          <!-- <div v-else>
            <Button type="warning" @click.stop="fh(orderInfo.group_order)">确认发货</Button>
            <Button type="info" v-print="'#dy'">打印订单</Button>
            <Button type="error" @click="ok">取消</Button>
          </div> -->

          </Col>

        </Row>
      </div>
    </Modal>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  data() {
    return {
      orderimg: ORDER_IMG,
      modelDel: false,
      delOrderId: "",
      currentpage: 1,
      order: "0",
      orderInfo: {},
      modal1: false,
      modal2: false,
      tabsName: "name1",
      pageNumber: 1,
      ordergroupOrder: "",
      orderusername: "",
      ordertel: "",
      label: h => {
        return h("div", [h("span", "全部订单")]);
      },
      columns7: [
        {
          title: "订单号",
          key: "group_order",
          width: 100
        },
        {
          title: "商品名称",
          key: "goods_name",
          render: (h, params) => {
            return h("div", [h("strong", params.row.goods_name)]);
          }
        },
        {
          title: "收货人",
          key: "consignee_name",
          sortable: true,
          width: 90
        },
        {
title:"收货人电话",
key:"tel",
width:120
        },
        {
title:"收货人地址",
key:'addrs',
render:(h,params)=>{
  return  params.row.province + params.row.city + params.row.county + params.row.address;
}
        },
        {
          title: "订单状态",
          key: "order_status",
          sortable: true,
          width: 110,
          render: (h, params) => {
            console.log(params.row.order_status);
            if (params.row.order_status == 0) {
              return "未付款";
            }
            if (params.row.order_status == 1) {
              return "已付款";
            }
            if (params.row.order_status == 2) {
              return "已发货";
            }
            if (params.row.order_status == 3) {
              return "已收货";
            }
            if (params.row.order_status == 5) {
              return "已退款";
            }
            if (params.row.order_status == 9) {
              return "已删除";
            }
          }
        },
        {
          title: "拼团状态",
          key: "group_status",
          sortable: true,
          width: 110,
          render: (h, params) => {
            let groupstatus = params.row.group_status;
            if (groupstatus == 1) {
              return "正在拼团";
            }
            if (groupstatus == 2) {
              return "拼团成功";
            }
            if (groupstatus == 3) {
              return "拼团失败";
            }
          }
        },
        {
          title: "配送方式",
          key: "delivery_mode",
          sortable: true,
          width: 110
        },
        {
          title: "商品数量",
          key: "number",
          width: 100
        },
        {
          title: "订单金额",
          key: "price",
          sortable: true,
          width: 110
        },
        {
          title: "支付时间",
          key: "create_datetime",
          sortable: true,
          width: 150
        },
        {
          title: "操作",
          key: "caozuo",
          width: 200,
          align: "center",
          render: (h, params) => {
            let _self = this;
            // console.log(params.row.order_status)
            if (params.row.order_status == 5 || params.row.order_status == 0) {
              return h("div", [
                h(
                  "Button",
                  {
                    style: {
                      marginLeft: "10px"
                    },
                    props: {
                      type: "primary",
                      size: "small"
                    },
                    on: {
                      click: e => {
                        let _self = this;
                        _self.modal2 = true;
                        $.ajax({
                          url: BASE_URL + "ordermanagement/groupActivityDetail",
                          type: "get",
                          data: {
                            groupOrder: params.row.group_order
                          },
                          success: function(data) {
                            console.log(data);
                            _self.orderInfo = data;
                            _self.orderInfo.userName =
                              params.row.consignee_name;
                            _self.orderInfo.tel = params.row.tel;
                            _self.orderInfo.adds =
                              params.row.province +
                              params.row.city +
                              params.row.county +
                              params.row.address;
                          }
                        });
                      }
                    }
                  },
                  "详情"
                )
              ]);
            } else {
              return h("div", [
                h(
                  "Button",
                  {
                    style: {
                      marginLeft: "10px"
                    },
                    props: {
                      type: "primary",
                      size: "small"
                    },
                    on: {
                      click: () => {
                        let _self = this;
                        let datas = {
                          out_trade_no: params.row.group_order,
                          all_total_fee: Math.round(params.row.price * 100),
                          refund_fee: Math.round(params.row.price * 100)
                        };
                        _self.delOrderId = datas;
                        _self.modelDel = true;

                        // console.log(datas);
                        // let _self = this
                      }
                    }
                  },
                  "退款"
                ),
                h(
                  "Button",
                  {
                    style: {
                      marginLeft: "10px"
                    },
                    props: {
                      type: "primary",
                      size: "small"
                    },
                    on: {
                      click: e => {
                        let _self = this;
                        _self.modal2 = true;
                        $.ajax({
                          url: BASE_URL + "ordermanagement/groupActivityDetail",
                          type: "get",
                          data: {
                            groupOrder: params.row.group_order
                          },
                          success: function(data) {
                            console.log(data);
                            _self.orderInfo = data;
                            _self.orderInfo.userName =
                              params.row.consignee_name;
                            _self.orderInfo.tel = params.row.tel;
                            _self.orderInfo.adds =
                              params.row.province +
                              params.row.city +
                              params.row.county +
                              params.row.address;
                          }
                        });
                      }
                    }
                  },
                  "详情"
                )
              ]);
            }
          }
        }
      ],
      data6: [],
      value: ""
    };
  },
  created() {
    this.getAllOrder(this.pageNumber);
    // this.groupSuccess(this.pageNumber);
  },
  methods: {
    delWork: function(orderid) {
      let _self = this;
      $.ajax({
        url: BASE_URL + "ordermanagement/refund",
        type: "get",
        data: orderid,
        success: function(data) {
          console.log(data);
          if (data) {
            _self.$Message.info("退款成功");
            if (_self.tabsName == "name1") {
              _self.getAllOrder(this.pageNumber);
            }
            if (_self.tabsName == "name2") {
              _self.getYfkOrder(this.pageNumber);
            }
            if (_self.tabsName == "name3") {
              _self.getYfhOrder(this.pageNumber);
            }
            if (_self.tabsName == "name4") {
              _self.getYshOrder(this.pageNumber);
            }
            if (_self.tabsName == "name5") {
              _self.groupSuccess(this.pageNumber);
            }
            if (_self.tabsName == "name6") {
              _self.groupFail(this.pageNumber);
            }
          } else {
            _self.$Message.info("退款失败");
            if (_self.tabsName == "name1") {
              _self.getAllOrder(this.pageNumber);
            }
            if (_self.tabsName == "name2") {
              _self.getYfkOrder(this.pageNumber);
            }
            if (_self.tabsName == "name3") {
              _self.getYfhOrder(this.pageNumber);
            }
            if (_self.tabsName == "name4") {
              _self.getYshOrder(this.pageNumber);
            }
            if (_self.tabsName == "name5") {
              _self.groupSuccess(this.pageNumber);
            }
            if (_self.tabsName == "name6") {
              _self.groupFail(this.pageNumber);
            }
          }
        }.bind(this)
      });
    },
    delok: function() {
      let _self = this;
      _self.delWork(_self.delOrderId);
    },
    delcancel: function() {},
    pages: function(e) {
      console.log(e);
      let _self = this;
      this.pageNumber = "";
      if (_self.tabsName == "name1") {
        this.pageNumber = e;
        _self.getAllOrder(this.pageNumber);
      }
      if (_self.tabsName == "name2") {
        this.pageNumber = e;
        _self.getYfkOrder(this.pageNumber);
      }
      if (_self.tabsName == "name3") {
        this.pageNumber = e;
        _self.getYfhOrder(this.pageNumber);
      }
      if (_self.tabsName == "name4") {
        this.pageNumber = e;
        _self.getYshOrder(this.pageNumber);
      }
      if (_self.tabsName == "name5") {
        this.pageNumber = e;
        _self.groupSuccess(this.pageNumber);
      }
      if (_self.tabsName == "name6") {
        this.pageNumber = e;
        _self.groupFail(this.pageNumber);
      }
    },
    fh: function(e) {
      $.ajax({
        url: BASE_URL + "ordermanagement/collectGoods",
        type: "get",
        data: {
          groupOrder: e
        },
        success: function(data) {
          console.log(data);
          this.modal2 = false;
          if (data) {
            let _self = this;

            if (_self.tabsName == "name1") {
              _self.getAllOrder(this.pageNumber);
            }
            if (_self.tabsName == "name2") {
              _self.getYfkOrder(this.pageNumber);
            }
            if (_self.tabsName == "name3") {
              _self.getYfhOrder(this.pageNumber);
            }
            if (_self.tabsName == "name4") {
              _self.getYshOrder(this.pageNumber);
            }
            if (_self.tabsName == "name5") {
              _self.groupSuccess(this.pageNumber);
            }
            if (_self.tabsName == "name6") {
              _self.groupFail(this.pageNumber);
            }
          }
        }.bind(this)
      });
    },
    dy() {
      window.print();
    },
    click: function(e) {
      console.log(e);
      let _self = this;
      _self.tabsName = e;
      _self.currentpage = 1;
      if (e == "name1") {
        _self.getAllOrder(1);
      } else if (e == "name2") {
        _self.getYfkOrder(1);
      } else if (e == "name3") {
        _self.getYfhOrder(1);
      } else if (e == "name4") {
        _self.getYshOrder(1);
      } else if (e == "name5") {
        _self.groupSuccess(1);
      } else if (e == "name6") {
        _self.groupFail(1);
      }
    },
    ss(e) {
      console.log(e);
    },
    orderBtn: function() {
      let _self = this;
      $.ajax({
        url: BASE_URL + "ordermanagement",
        type: "GET",
        data: {
          groupOrder: _self.ordergroupOrder,
          username: "",
          tel: "",
          date: "",
          pageNumber: 1,
          pageSize: "1000"
        },
        success: function(data) {
          console.log(data);
          _self.data6 = data.list;
        }.bind(_self)
      });
    },
    usernameBtn: function() {
      let _self = this;
      $.ajax({
        url: BASE_URL + "ordermanagement",
        type: "GET",
        data: {
          groupOrder: "",
          username: _self.orderusername,
          tel: "",
          date: "",
          pageNumber: 1,
          pageSize: "1000"
        },
        success: function(data) {
          console.log(data);
          _self.data6 = data.list;
        }.bind(_self)
      });
    },
    telBtn: function() {
      let _self = this;
      $.ajax({
        url: BASE_URL + "ordermanagement",
        type: "GET",
        data: {
          groupOrder: "",
          username: "",
          tel: _self.ordertel,
          date: "",
          pageNumber: 1,
          pageSize: "1000"
        },
        success: function(data) {
          console.log(data);
          _self.data6 = data.list;
        }.bind(_self)
      });
    },
    getAllOrder: function(pageNumber) {
      console.log(pageNumber);
      //全部订单
      let _self = this;
      $.ajax({
        url: BASE_URL + "ordermanagement",
        type: "GET",
        data: {
          groupOrder: "",
          username: "",
          tel: "",
          date: "",
          pageNumber: pageNumber,
          pageSize: "10"
        },
        success: function(data) {
          console.log(data);
          _self.data6 = data.list;
        }.bind(_self)
      });
    },
    getYfkOrder: function(pageNumber) {
      let _self = this;
      $.ajax({
        url: BASE_URL + "ordermanagement/groupActivityDetailsByYF",
        type: "GET",
        data: {
          groupOrder: "",
          username: "",
          tel: "",
          date: "",
          pageNumber: pageNumber,
          pageSize: 10
        },
        success: function(data) {
          console.log(data);
          _self.data6 = data.list;
        }.bind(this)
      });
    },
    getYfhOrder: function(pageNumber) {
      let _self = this;
      $.ajax({
        url: BASE_URL + "ordermanagement/groupActivityDetailsByYFH",
        type: "GET",
        data: {
          groupOrder: "",
          username: "",
          tel: "",
          date: "",
          pageNumber: pageNumber,
          pageSize: 10
        },
        success: function(data) {
          console.log(data);
          _self.data6 = data.list;
        }.bind(this)
      });
    },
    getYshOrder: function(pageNumber) {
      let _self = this;
      $.ajax({
        url: BASE_URL + "ordermanagement/groupActivityDetailsByYSH",
        type: "GET",
        data: {
          groupOrder: "",
          username: "",
          tel: "",
          date: "",
          pageNumber: pageNumber,
          pageSize: 10
        },
        success: function(data) {
          console.log(data);
          _self.data6 = data.list;
        }.bind(this)
      });
    },
    groupSuccess: function(pageNumber) {
      let _self = this;
      //拼团成功数据信息
      let datas = {
        groupOrder: "",
        username: "",
        tel: "",
        date: "",
        pageNumber: pageNumber,
        pageSize: 10
      };
      $.ajax({
        url: BASE_URL + "ordermanagement/groupSuccess",
        type: "get",
        data: datas,
        success: function(data) {
          console.log(data);
          if (data.list.length > 0) {
            _self.data6 = data.list;
          } else {
            _self.data6 = [];
          }
        }.bind(this)
      });
    },
    groupFail: function(pageNumber) {
      let _self = this;
      //拼团失败数据信息
      let datas = {
        groupOrder: "",
        username: "",
        tel: "",
        date: "",
        pageNumber: pageNumber,
        pageSize: 10
      };
      $.ajax({
        url: BASE_URL + "ordermanagement/groupFail",
        type: "get",
        data: datas,
        success: function(data) {
          console.log(data);
          console.log(data);
          if (data.list) {
            _self.data6 = data.list;
          } else {
            _self.data6 = [];
          }
        }.bind(this)
      });
    },
    handleAdd() {
      this.index++;
      this.formDynamic.items.push({
        value: "",
        index: this.index,
        status: 1
      });
    },
    ok() {
      // console.log(this.formValidate, this.formDynamic, this.list);
      this.modal2 = false;
      //   this.$Message.info("Clicked ok");
      //   this.data6.push({ name: this.value, spsl: "0" });
    },
    cancel() {
      this.$Message.info("Clicked cancel");
    },
    remove(index) {
      this.data6.splice(index, 1);
    },
    handleSubmit(name) {
      console.log(name);
      this.$refs[name].validate(valid => {
        if (valid) {
          this.$Message.success("Success!");
        } else {
          this.$Message.error("Fail!");
        }
      });
    },
    handleReset(name) {
      this.$refs[name].resetFields();
    }
  }
};
</script>

<style scoped>
</style>
